package com.ordering.dao.login.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.ordering.dao.login.AdminLoginDao;
import com.ordering.entity.Manager;
import com.ordering.util.HibernateUtil;

public class AdminLoginDaoImpl implements AdminLoginDao
{
    private SessionFactory sessionFactory;
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    
    @Override
    public Manager login(Manager manager)
    {
        Session s=null;
        try{
            s=HibernateUtil.getSession();
           
           //from后面是对象，不是表名
            String hql="from Manager where loginName=:loginName and password =:password";//使用命名参数，推荐使用，易读。
            Query query=s.createQuery(hql);
            query.setString("loginName", manager.getLoginName());
            query.setString("password", manager.getPassword());
            List<Manager> managers =query.list();
            if(managers==null||managers.size()==0){
                return null;
            }
            for(Manager user:managers){
                return user;
            }
        }finally{
            if(s!=null)
                s.close();
        }
        return null;
    }

    @Override
    public boolean logout(Manager manager)
    {
        // TODO Auto-generated method stub
        return false;
    }

}
